//
//  FLMManageOrderListController.m
//  FLMSuperS
//
//  Created by xiaoyang on 16/9/16.
//  Copyright © 2016年 FaLaoMiaoNetworkTechnologyCo. All rights reserved.
//

#import "FLMManageOrderListController.h"
#import "FLMManageOrderListCell.h"
#import "FLMOrderSearchView.h"
#import "FLMOrderDetailController.h"

@interface FLMManageOrderListController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataArr;
@property (nonatomic,strong) FLMOrderSearchView *searchView;

@end

@implementation FLMManageOrderListController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self layoutUI];
}

- (NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc]init];
    }
    return _dataArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)layoutUI
{
    if (!_searchView) {
        _searchView = [[FLMOrderSearchView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 35)];
        [self.view addSubview:_searchView];
        __weak typeof (self)weakSelf = self;
        [_searchView setSearchBlock:^(UITextField *textField) {
            if (!textField.text.length) {
                [SVProgressHUD showErrorWithStatus:@"搜索订单号不能为空"];
                return ;
            }
            [weakSelf searchData];
        }];
        
    }
    
    self.dataArr = [@[@"1",@"1"] mutableCopy];
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_searchView.frame), ScreenW, ScreenH) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
        [_tableView registerClass:[FLMManageOrderListCell class] forCellReuseIdentifier:@"FLMManageOrderListCell"];
        _tableView.separatorInset = UIEdgeInsetsZero;
        if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            _tableView.layoutMargins = UIEdgeInsetsZero;
        }

        [self.view addSubview:_tableView];
        __weak typeof (self)weakSelf = self;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakSelf refreshData];
        }];
        
        _tableView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
            [weakSelf loadMoreData];
        }];
    }
    
    
}



#pragma mark --UITableViewDelegate && UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    FLMManageOrderListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FLMManageOrderListCell"];
    [cell configCellWithModel:nil];
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 88;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    FLMOrderDetailController *detailVC = [[FLMOrderDetailController alloc]init];
    detailVC.title = [NSString stringWithFormat:@"%@详情",self.orderTypeName];
    [self.navigationController pushViewController:detailVC animated:YES];
}

#pragma mark --私有方法
/**
 *  搜索
 */
- (void)searchData
{
    
}

/**
 *  刷新数据
 */

- (void)refreshData
{
    [self.tableView.mj_header endRefreshing];
}

/**
 *  加载数据
 */

- (void)loadMoreData
{
    [self.tableView.mj_footer endRefreshing];
}

@end
